import { Button } from "antd";
const checkPermission = (role, allowedRoles) => {
    return allowedRoles.includes(role);
};

const RoleButton = ({ role, allowedRoles = ['admin'], onClick, children, ...rest }) => {
    let hasPermission = null
    if (!role) hasPermission = true
    else hasPermission = checkPermission(role, allowedRoles);
    return <Button onClick={onClick} disabled={!hasPermission} {...rest} > {children} </Button>;

};

const RoleLink = ({ role, allowedRoles = ['admin'], onClick, children, ...rest }) => {
    let hasPermission = null
    if (!role) hasPermission = true
    else hasPermission = checkPermission(role, allowedRoles);
    return <Button type="link" onClick={onClick} disabled={!hasPermission} {...rest} >{children} </Button>;
};

export {
    RoleButton, RoleLink
}